package com.jml.springsecurity.core.social.qq.connect;

import com.jml.springsecurity.core.social.qq.api.QQ;
import com.jml.springsecurity.core.social.qq.api.QQImpl;
import org.springframework.social.oauth2.AbstractOAuth2ServiceProvider;
import org.springframework.social.oauth2.OAuth2Template;


//抽象类AbstractOAuth2ServiceProvider的泛型是指api接口的类型
//实现这个抽象类需要重构父类的构造函数
public class QQServiceProvider extends AbstractOAuth2ServiceProvider<QQ> {

	private String appId;

	//第一步，将用户导向用户认证服务器的获取授权码的url
	private static final String URL_AUTHORIZE = "https://graph.qq.com/oauth2.0/authorize";

	//第四步，申请令牌得到token的url
	private static final String URL_ACCESS_TOKEN = "https://graph.qq.com/oauth2.0/token";

	//appId和appSecret，是注册成功后QQ互联给的
	public QQServiceProvider(String appId, String appSecret) {
		//这个就是第1-5步，模板化获取access_Token
		super(new QQOAuth2Template(appId, appSecret, URL_AUTHORIZE, URL_ACCESS_TOKEN));
		this.appId = appId;
	}

	//getApi就是对第6步api的实例化
	@Override
	public QQ getApi(String accessToken) {
		return new QQImpl(accessToken, appId);
	}

}
